{{ template "header" . }}
<ol class="breadcrumb">
  <li class="breadcrumb-item"><a href="/">Home</a></li>
  <li class="breadcrumb-item active">Volumes</li>
</ol>

<div class="container">
  <div class="row">
    <div class="col-md-12">
      <div class="card">
        <div class="card-body">
          <div class="row">
            <div class="col-md-12">
              <h4 class="card-title">Volumes</h4>
              <div class="small text-muted" style="margin-top:-10px;">Total: {{ len .Volumes }}</div>
            </div>
          </div>
          <br>
          <form method="post" action="{{ Url "volume-add-form" }}">{{ CSRFField .Request }}
            <div class="form-group row">
              <div class="col-md-2">
                <input required="required" class="form-control" name="Name" id="Name" aria-describedby="nameHelp">
                <small id="nameHelp" class="form-text text-muted">Volume name</small>
              </div>
              <div class="col-md-2">
                <select required="required" class="JS-QueryStringSelector custom-select" name="NodeId" data-exclusive="true" data-paramname="node" data-url="{{ Url "volume-list" }}">
                  <option value="">- - -</option>
                  {{ range .Nodes }}
                  <option {{ if eq $.NodeId .Id }}selected{{ end }} value="{{ .Id }}">{{ .Id }}</option>
                  {{ end }}
                </select>
                <small id="nameHelp" class="form-text text-muted">Node</small>
              </div>
              <div class="col-md-2">
                <select required="required" class="JS-QueryStringSelector custom-select" name="Pool" data-paramname="pool" data-url="{{ Url "volume-list" }}">
                  <option value="">- - -</option>
                  {{ range .Pools }}
                  <option {{ if eq $.Pool .Name }}selected{{ end }} value="{{ .Name }}">{{ if not $.NodeId }}{{ .NodeId }}::{{ end }}{{ .Name }} ({{ .Free.Bytes | HumanizeBytes }} free {{ .UsagePercent }}% used)</option>
                  {{ end }}
                </select>
                <small id="nameHelp" class="form-text text-muted">Pool</small>
              </div>
              <div class="col-md-2">
                <div class="input-group">
                  <input required="required" class="form-control" name="SizeValue" min="1" id="Size" value="10" type="number">
                  <div class="input-group-append">
                    <select style="border-top-left-radius: 0; border-bottom-left-radius: 0;" name="SizeUnit" class="form-control">
                      <option value="B">B</option>
                      <option value="K">K</option>
                      <option value="M">M</option>
                      <option selected value="G">G</option>
                    </select>
                  </div>
                </div>
                <small class="form-text text-muted">Size</small>
              </div>
              <div class="col-md-2">
                <select required="required" class="form-control" name="Format">
                  {{ range .VolumeFormats }}
                  <option value="{{ . }}">{{ . }}</option>
                  {{ end }}
                </select>
                <small id="nameHelp" class="form-text text-muted">Format</small>
              </div>
              <div class="col-md-2">
                <button class="btn btn-block btn-primary"
                  data-loading="<i class='icon-refresh icons'></i> Creating machine..." type="submit">Add Volume</button>
              </div>
            </div>
          </form>

          <div class="row">
            <div class="col-md-12 mt-5">
              <table class="table">
                <thead class="thead-light">
                  <tr>
                    <th>Name</th>
                    <th>Pool</th>
                    <th>Node</th>
                    <th>Format</th>
                    <th>Size</th>
                    <th>AttachedTo</th>
                    <th>Actions</th>
                  </tr>
                </thead>
                <tbody>
                  {{ range .Volumes }}
                  <tr>
                    <td>{{ .Name }}</td>
                    <td>{{ .Pool }}</td>
                    <td>{{ .NodeId }}</td>
                    <td>{{ .Format }}</td>
                    <td>{{ .Size.Bytes | HumanizeBytes }}</td>
                    <td>
                      {{ if .AttachedTo }}
                      <a href="{{ Url "virtual-machine-detail" "id" .AttachedTo "node" .NodeId }}">{{ .AttachedTo }}</a>
                      {{ end }}
                    </td>
                    <td>
                      <a title="Clone" href="{{ Url "volume-clone-form" "path" .Path "node" .NodeId }}">C</a>
                      | <a title="Resize" href="{{ Url "volume-resize-form" "path" .Path "node" .NodeId }}">R</a>
                      {{ if not .Metadata.Protected }}
                      | <a title="Delete" style="color: red;" href="{{ Url "volume-delete-form" "path" .Path "node" .NodeId }}">D</a>
                      {{ end }}
                    </td>
                  </tr>
                  {{ end }}
                </tbody>
              </table>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
{{ template "footer" . }}
